package br.com.aeso.bancoCurriculo.controller.curriculo;

import java.io.Serializable;
import java.util.ArrayList;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import br.com.aeso.bancoCurriculo.controller.util.ComumController;
import br.com.aeso.bancoCurriculo.model.comum.excecoes.NegocioException;
import br.com.aeso.bancoCurriculo.model.curriculo.impl.CurriculoImpl;
import br.com.aeso.bancoCurriculo.model.usuario.impl.UsuarioImpl;
import br.com.aeso.bancoCurriculo.model.util.Fachada;


@ManagedBean
@ViewScoped
public class CurriculoController extends ComumController implements Serializable  {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Fachada fachada;
	private CurriculoImpl curriculo;

	private  ArrayList<CurriculoImpl> curriculosBean = new ArrayList<>();


	private String nomeFiltro;
	private String radioButton;
	

	public CurriculoController() {
		fachada = Fachada.getInstancia();
		curriculo = (CurriculoImpl) fachada.criarCurriculo();
		this.nomeFiltro="";
		this.radioButton= "";
	pesquisarTodosCurriculos();
	
	}


	public String getRadioButton() {
		return radioButton;
	}


	public void setRadioButton(String radioButton) {
		
		this.radioButton = radioButton;
	}


	public CurriculoImpl getCurriculo() {
		return curriculo;
	}

	public void setCurriculo(CurriculoImpl curriculo) {
		this.curriculo = curriculo;
	}

	public String getNomeFiltro() {
		return nomeFiltro;
	}

	public void setNomeFiltro(String nomeFiltro) {
		this.nomeFiltro = nomeFiltro;
	}

	public ArrayList<CurriculoImpl> pesquisarTodosCurriculos() {

		ArrayList<CurriculoImpl> curriculos;

		String filtroNome = getNomeFiltro();
		curriculos = fachada.pesquisarTodosCurriculos(filtroNome,getRadioButton());
		this.setCurriculosBean(curriculos);
			return curriculos;
	}

	public void addCurriculo() throws NegocioException {

		UsuarioImpl usuario = (UsuarioImpl) getAttributeSession(ComumController.ATRIBUTO_SESSAO_USUARIO_LOGADO);
		curriculo.getUsuario().setChavePrimaria(usuario.getChavePrimaria());
		fachada.inserirCurriculo(curriculo);

		FacesContext.getCurrentInstance().addMessage(
				null,
				new FacesMessage(FacesMessage.SEVERITY_INFO, "",
						"Curriculo adicionado com Sucesso !"));

	}


	public ArrayList<CurriculoImpl> getCurriculosBean() {
		return curriculosBean;
	}

	public void setCurriculosBean(ArrayList<CurriculoImpl> curriculosBean) {
		this.curriculosBean = curriculosBean;
	}

}
